#include<bits/stdc++.h>
using namespace std;
int t;
int main(){
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    cin>>t;
    while(t--){
        int n, m, l, v;
        cin>>n>>m>>l>>v;
        int ans1 = 0, ans2, a[100003], b[100003], c[100003], last = -1;
        for(int i = 1;i <= n;i++){
            cin>>a[i]>>b[i]>>c[i];
        }
        for(int i = 1;i <= m;i++){
            int x;
            cin>>x;
            last = max(last, x);
        }
        for(int i = 1;i <= n;i++){
            if(b[i] > v && a[i] <= last)ans1++;
        }
        if(ans1 == 0)ans2 = m;
        else ans2 = m - 1;
        cout<<ans1<<' '<<ans2<<endl;
    }
}
